#include "subwindowplaytextfunctor.h"
#include "mainwindow.h"
#include "textplayer.h"
#include "common.h"

#include <QThread>

SubWindowPlayTextFunctor::SubWindowPlayTextFunctor(int windowNo, const QString &text):
		m_WindowNo(windowNo)
		,m_Text(text)
{
}

void SubWindowPlayTextFunctor::operator ()()
{
	MainWindow* mainWindow = MainWindow::instance();

	Qt::ConnectionType connectionType;
	if(QThread::currentThread() == g_MainThread)
	{
		connectionType = Qt::DirectConnection;
	}
	else
	{
		connectionType = Qt::BlockingQueuedConnection;
	}

	ValuePacket valuePacket;
	valuePacket.insert(TextPlayer::TextName, m_Text);
	QMetaObject::invokeMethod(
			mainWindow
			,"setSubWindowContent"
			,connectionType
			,Q_ARG(int, m_WindowNo)
			,Q_ARG(PlayerType,LocalText)
			,Q_ARG(ValuePacket, valuePacket));

}
